#!/bin/bash

# 快速启动脚本

echo "============================================="
echo "  LLM 内容安全检测系统 - 快速启动"
echo "============================================="

# 1. 检查Python环境
echo ""
echo "1️⃣  检查Python环境..."
if ! command -v python3 &> /dev/null; then
    echo "❌ 未找到Python3，请先安装Python 3.9+"
    exit 1
fi

PYTHON_VERSION=$(python3 --version | awk '{print $2}')
echo "✅ Python版本: $PYTHON_VERSION"

# 2. 安装依赖
echo ""
echo "2️⃣  安装依赖包..."
pip3 install -r requirements.txt

# 3. 准备数据
echo ""
echo "3️⃣  准备训练数据..."
if [ ! -f "data/train.csv" ]; then
    echo "正在划分数据集..."
    python3 prepare_data.py
else
    echo "✅ 数据集已存在，跳过"
fi

# 4. 训练模型
echo ""
echo "4️⃣  训练模型..."
if [ ! -d "models/safety_classifier" ]; then
    echo "⏰ 开始训练模型（Mac M4 预计 2-4 小时）..."
    echo "💡 您可以按 Ctrl+C 取消训练，稍后手动运行："
    echo "   cd models && python3 train_model.py"
    echo ""
    read -p "是否现在开始训练？(y/N): " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        cd models && python3 train_model.py
        cd ..
    else
        echo "⏭️  跳过训练，请稍后手动训练"
    fi
else
    echo "✅ 模型已存在，跳过训练"
fi

# 5. 启动API服务
echo ""
echo "5️⃣  启动API服务..."
echo "🌐 服务地址: http://localhost:8000"
echo "📚 API文档: http://localhost:8000/docs"
echo ""
cd api && python3 main.py
